<link href="/ast/layui/css/layui.css" rel="stylesheet">
<script src="/ast/layui/layui.js"></script>
<div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
            <div class="demo-login-container">
              <div class="layui-form-item">
                <div class="layui-input-wrap">
                  <input type="text" id="bname" value="" lay-verify="required" placeholder="书名（10字内）" lay-reqtext="name" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-wrap">
                  <input type="text" id="bcontent" value="" style="height: 60px;" lay-verify="required" placeholder="书述（大概内容）50字内" lay-reqtext="jdcon" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-wrap">
                  <input type="text" id="burl" value="" lay-verify="required" placeholder="书图(图片链接)太长的话建议短链接" lay-reqtext="url" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
              </div>
              <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" id='button-add'  lay-submit lay-filter="add">新增</button>
              </div>
             
            </div>
          </div>

<script language="javascript" type="text/javascript">
    if (window.self == window.top) {
        alert("暂无通行证");
        location.href = "./";
    }
</script>
<script>
layui.use('form', function(){
  var form = layui.form;
  var layer = layui.layer;
  form.render();
  return false;
});
function fetchcardadd(){
    const b_name = document.getElementById('bname').value;
    const b_content = document.getElementById('bcontent').value;
    const b_url = document.getElementById('burl').value;
    const writer = sessionStorage.getItem('user');
    if(b_name === '' || b_content === '' || b_url == ''){
        layer.msg('请填写完整信息', {icon: 5});
        return false;
    }
    if(b_name.length > 10){
        layer.msg('书名太长', {icon: 5});
        return false;
    }
    if(b_content.length > 50){
        layer.msg('书述太长', {icon: 5});
        return false;
    }
    var loadingz = layer.load(2);
    fetch('/cofd/novel.php?cz=add&name='+b_name+'&content='+b_content+'&url='+b_url+'&user='+writer)
    .then(response => response.json())
    .then(data => {
        layer.close(loadingz);
        if(data.code === 200){
            layer.msg(data.msg, {icon: 6});
        }else{
            layer.msg(data.msg, {icon: 5});
        }
        setTimeout(function(){
            window.parent.location.reload();
        }, 1000);
    })
}
document.getElementById('button-add').addEventListener('click', fetchcardadd)
</script>